package com.mmm.station.base.service;

import com.github.pagehelper.PageInfo;

import com.mmm.station.base.dao.BaseDao;
import com.mmm.station.base.entity.BaseEntity;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class BaseServiceImpl<T extends BaseEntity<T>,D extends BaseDao<T>> implements BaseService<T> {

	/**
	 * 持久层对象
	 */
	@Autowired
	protected D dao;


	@Override
	public T selectByKey(Long id) {
		System.out.println("-=-=-=-=-=---shu");

		System.out.println(dao.toString());

		return dao.selectByKey(id);
	}

	@Override
	public T selectByEntity(T entity) {
		return dao.selectByEntity(entity);
	}


	public T selectByConditions(Map<String,String> conditions) {
		return dao.selectByConditions(conditions);
	}
	@Override
	public PageInfo<List<T>> selectPage(Map<String, String> conditions) {
		List<T> resList = null;
		if (conditions.get("pageNum")!=null&&!"".equals(conditions.get("pageNum")) && conditions.get("pageSize")!=null && !"".equals(conditions.get("pageSize"))) {
			resList= dao.selectPage(conditions, new RowBounds(Integer.parseInt(conditions.get("pageNum")), Integer.parseInt(conditions.get("pageSize"))));
		}else {
			resList= new ArrayList<T>();
		}
		PageInfo<List<T>> pageInfo = new PageInfo(resList);
		return pageInfo;
	}




	@Override
	public List<T> selectList(Map<String, String> conditions) {
		return dao.selectList(conditions);
	}

	@Override
	public List<T> selectList(T entity) {
		return dao.selectList(entity);
	}

	@Override
	public int insert(T entity) {
		return dao.insert(entity);
	}

	@Override
	public int insertSelective(T entity) {
		return dao.insertSelective(entity);
	}



	@Override
	public int updateSelective(T entity) {
		return dao.updateSelective(entity);
	}
	public int updateSelective(Map<String,String> conditions) {
		return dao.updateSelective(conditions);
	}

	@Override
	public int update(T entity) {
		return dao.update(entity);
	}

	@Override
	public int deleteByKey(Long id) {
		return dao.deleteByKey(id);
	}

	@Override
	public int delete(T entity) {
		return dao.delete(entity);
	}
	public int delete(Map<String,String> conditions) {
		return dao.delete(conditions);
	}

	@Override
	public int deleteByIds(List<Long> ids) {
		return dao.deleteByIds(ids);
	}


}
